package openadmin.model.control;

/**
 * <desc>class that stores the basic information of ActionClass</desc>
 * <responsibility>Represents all the classes that have actions for users</responsibility>
 * <coperation>Interface Base - Class Action - Class view </coperation>
 * @version  0.1
 * Created 10-05-2008
 * Modifier 18-09-2009 
 * Author Alfred Oliver
*/

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import openadmin.dao.Base;
//import openadmin.dao.FieldProperties;


import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;


@Entity
@Table(name = "actionclass", schema = "control", uniqueConstraints = @UniqueConstraint(columnNames="description"))
public class ActionClass implements Base, java.io.Serializable {

	/** Field that contains the identifier*/	
	@Id	
	@GeneratedValue(strategy = GenerationType.IDENTITY)		
	private Integer id;
	
	/** Field that contains the description*/	
	@Column(unique = true)
	@Length(max = 30)
	private String description;	
	

	/** Transient attribute that means that the system should make a log on any JPA operation of this class*/
	@Transient 
	private boolean debuglog = true;
	
	/** Transient attribute that means that the system should make a historic on any JPA operation of this class*/
	@Transient
	boolean historiclog = false;	

	/** Field that contains the actions of the class*/
	//@OneToMany(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER, mappedBy = "actionClass")
	//private Set<Action> actions = new HashSet<Action>(0);	
	
	/** Field that contains the actions of the class*/
	//@OneToMany(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER, mappedBy = "actionClass")
	//private Set<View> views = new HashSet<View>(0);	
	
	
	/**
	 * Constructor of the class ActionClass.
	 * without parameters
	 */
	public ActionClass() {
		
	}

	/**
	 * Constructor of the class ActionClass.
	 * @param pDescription, is the description, (unique value), of the ActionClass
	 */
	public ActionClass(String pDescription) {
		
		this.description = pDescription.toLowerCase();
	}
	
	/**
	 * <desc> Accessor of reading which gives us the identifier</desc>
	 * <pre> x is an instance of ActionClass</pre>
	 * <post> the return is the identifier of x </post>
	 * @return Identifier of object
	 */		
	public Integer getId() {
		return this.id;
	}

	/**
	 * <desc> Accessor of writing which gives us the identifier</desc>
	 * <pre> x is an instance of ActionClass</pre>
	 * <post> the identifier is stored</post>
	 * @param pId, is the identifier of object
	 */	
	//@FieldProperties(nia = 1)
	public void setId(Integer pId) {
		this.id = pId;
	}
	
	/**
	 * <desc> Accessor of reading which gives us the description, unique value</desc>
	 * <pre> x is an instance of ActionClass</pre>
	 * <post> the return is the description of x </post>
	 * @return description of object
	 */	
	public String getDescription() {
		return this.description;
	}

	/**
	 * <desc> Accessor of writing which gives us the description</desc>
	 * <pre> x is an instance of ActionClass</pre>
	 * <post> the description is stored</post>
	 * @param pDescription, description of object, unique value
	 */	
	public void setDescription(String pDescription) {
		this.description = pDescription.toLowerCase();		
	}

	/**
	 * <desc> Accessor of reading which gives us the actions of class</desc>
	 * <pre> x is an instance of ActionClass</pre>
	 * <post> the return is the actions of x </post>
	 * @return actions of ActionClass
		
	public Set<Action> getActions() {
		return this.actions;
	}

	/**
	 * <desc> Accessor of writing which gives us the actions</desc>
	 * <pre> x is an instance of ActionClass</pre>
	 * <post> the actions is stored</post>
	 * @param pActions, actions of ActionClass
	
	public void setActions(Set<Action> pActions) {
		this.actions = pActions;
	}
	
	/**
	 * <desc> Accessor of reading which gives us the viewa of class</desc>
	 * <pre> x is an instance of ActionClass</pre>
	 * <post> the return is the viewa of x </post>
	 * @return views of ActionClass
		
	public Set<View> getViews() {
		return this.views;
	}

	/**
	 * <desc> Accessor of writing which gives us the views</desc>
	 * <pre> x is an instance of ActionClass</pre>
	 * <post> the views are stored</post>
	 * @param pViews, actions of ActionClass
	 
	public void setViews(Set<View> pViews) {
		this.views = pViews;
	}
	*/
	public boolean getDebugLog() {
			return debuglog;
	}
			
	
	public void setDebugLog(boolean pDebuglog) {
		debuglog = pDebuglog;
	}
	
	public boolean getHistoricLog() {
		return historiclog;
	}

	public void setHistoricLog(boolean historiclog) {
		this.historiclog = historiclog;
	}
		
	@Override
	public String toString() {
		return this.getDescription();
	}	 	 	

}
